package com.dingreading.cloud.web.service.impl;

import com.dingreading.cloud.common.util.DateUtil;
import com.dingreading.cloud.web.entity.table.WxAcecGzhUserTableDef;
import com.mybatisflex.core.table.TableDef;
import com.mybatisflex.core.update.UpdateChain;
import com.mybatisflex.spring.service.impl.ServiceImpl;
import com.dingreading.cloud.web.entity.WxAcecGzhUser;
import com.dingreading.cloud.web.mapper.WxAcecGzhUserMapper;
import com.dingreading.cloud.web.service.WxAcecGzhUserService;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 *  服务层实现。
 *
 * @author Administrator
 * @since 2024-12-23
 */
@Service
public class WxAcecGzhUserServiceImpl extends BaseServiceImpl<WxAcecGzhUserMapper, WxAcecGzhUser, WxAcecGzhUserTableDef> implements WxAcecGzhUserService {

    @Override
    protected WxAcecGzhUserTableDef getTable() {
        return WxAcecGzhUserTableDef.wxAcecGzhUser;
    }

    @Override
    public List<WxAcecGzhUser> getByOpenid(String openid) {
        return getMapper().selectListByCondition(table.openid.eq(openid));
    }

    @Override
    public void updateUnsubscribeTime(String openid) {
        String time = DateUtil.getNowDatetimeStr();
        UpdateChain.of(WxAcecGzhUser.class)
                .set(table.subscribe, 0)
                .set(table.unsubscribeTime, time)
                .set(table.editTime, time)
                .where(table.openid.eq(openid))
                .update();
    }

    @Override
    public void updateSource(String openid, String source) {
        UpdateChain.of(WxAcecGzhUser.class)
                .set(table.source, source)
                .where(table.openid.eq(openid))
                .update();
    }
}
